package com.bawei.a2010douyin.ui.tuijian;

import android.widget.ImageView;

import com.bawei.a2010douyin.R;
import com.bawei.a2010douyin.base.mvp.BaseView;
import com.bawei.a2010douyin.base.utils.GlideUtils;
import com.bawei.a2010douyin.entity.CommentEntity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import androidx.annotation.NonNull;

public class CommentAdapter extends BaseQuickAdapter<CommentEntity, BaseViewHolder> {
    public CommentAdapter(int layoutResId) {
        super(layoutResId);
    }


    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, CommentEntity commentEntity) {
        ImageView imageView = baseViewHolder.getView(R.id.iv_user);
        GlideUtils.getInstance().loadCircleImage(getContext(),commentEntity.getIcon(),imageView);
        baseViewHolder.setText(R.id.tv_username,commentEntity.getUsername());
        baseViewHolder.setText(R.id.tv_message,commentEntity.getMsg());
        baseViewHolder.setText(R.id.tv_time,commentEntity.getCreatetime()+"");
        if(commentEntity.getCreatetime() != null){
            //2分钟前 刚刚  一小时前：xxx分钟前  1天前：xxx小时前  2天前：昨天
            String createtime = commentEntity.getCreatetime();//字符串
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            try {
                Date date = simpleDateFormat.parse(createtime);//将字符串--》Date格式
                long time = date.getTime();//毫秒值
                long cha = System.currentTimeMillis() - time;//时间差
                if(cha<2*60*1000){///2分钟前 刚刚
                    baseViewHolder.setText(R.id.tv_time,"刚刚");
                }else if(cha < 60*60*1000){//一小时前：xxx分钟前
                    baseViewHolder.setText(R.id.tv_time,cha/1000/60+"分钟前");
                }else if(cha < 24 *  60*60*1000){//1天前：xxx小时前
                    baseViewHolder.setText(R.id.tv_time,cha/1000/60/60+"小时前");
                }else if(cha < 2*24 *  60*60*1000) {// 2天前：昨天
                    baseViewHolder.setText(R.id.tv_time,"昨天");
                }else {
                    baseViewHolder.setText(R.id.tv_time,createtime+"");
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }




    }
}
